'''
Created on 05/04/2013

@author: tsantana
'''

from google.appengine.ext import db

class Permission(db.Model):
    
    @property
    def name(self):
        return self.key().name()
    

class Role(db.Model):

    status = db.IntegerProperty()
    permission = db.ReferenceProperty(Permission)
    @property
    def name(self):
        return self.key().name()
    
class Menu(db.Model):
    title = db.StringProperty()
    role = db.ReferenceProperty(Role)
    
class MenuItem(db.Model):
    name = db.StringProperty()
    link = db.StringProperty()
    menu = db.ReferenceProperty(Menu)
    
class User(db.Model):
    
    first_name = db.StringProperty()
    last_name = db.StringProperty()
    #login = db.StringProperty()
    password = db.StringProperty()
    birth_date = db.DateProperty()
    creation_date = db.DateTimeProperty(auto_now_add=True)
    last_update_date = db.DateTimeProperty(auto_now=True)
    status = db.IntegerProperty()
    last_password_change_date = db.DateTimeProperty()
    role = db.ReferenceProperty(Role)
    
    @property
    def login(self):
        return self.key().name()
    
class Product(db.Model):
    
    name=db.StringProperty()
    description=db.TextProperty()
    unit_type=db.StringProperty()
    unit_price=db.FloatProperty()
    brand=db.StringProperty()
    model=db.StringProperty()
    fabrication_date=db.DateProperty()
    registration_date=db.DateTimeProperty(auto_now_add=True)
    last_update_date=db.DateTimeProperty(auto_now=True)
    quantity_in_stock=db.IntegerProperty()
    
class Position(db.Model):
    
    name=db.StringProperty()
    description=db.TextProperty()

class Department(db.Model):

    @property
    def name(self):
        return self.key().name()
    
class Employee(User):
    
    employee_code=db.StringProperty()
    position=db.ReferenceProperty(Position)
    department=db.ReferenceProperty(Department)
    manager=db.SelfReferenceProperty()
    
class SalesPerson(Employee):
    
    has_comission=db.BooleanProperty()
    commission_rate=db.FloatProperty()
    
class Commision(db.Model):
    
    sales_person=db.ReferenceProperty(SalesPerson)
    status=db.IntegerProperty()
    amount=db.FloatProperty()
    registration_date=db.DateTimeProperty(auto_now_add=True)
    last_update_date=db.DateTimeProperty(auto_now=True)
    closure_date=db.DateTimeProperty()

class Sale(db.Model):
    
    sales_person=db.ReferenceProperty(SalesPerson)
    customer_name=db.StringProperty()
    comment=db.TextProperty()
    status=db.IntegerProperty()
    registration_date=db.DateTimeProperty(auto_now_add=True)
    
class SaleItem(db.Model):
    
    sale=db.ReferenceProperty(Sale)
    quantity=db.FloatProperty()
    


    
    
    